import request from '../utils/request'
export function fetchList(parentId,params) {
  return request({
    url:'/nftType/getTreeList/',
    method:'post',
    params:params
  })
}
export function deleteProductCate(data) {
  return request({
    url:'/nftType/delete/',
    method:'post',
    data:data
  })
}

export function createProductCate(data) {
  return request({
    url:'/nftType/create',
    method:'post',
    data:data
  })
}

export function updateProductCate(data) {
  return request({
    url:'/nftType/update/',
    method:'post',
    data:data
  })
}

export function getProductCate(id) {
  return request({
    url:'/nftType/'+id,
    method:'get',
  })
}

export function updateShowStatus(data) {
  return request({
    url:'/nftType/updateShowStatus',
    method:'post',
    data:data
  })
}

export function updateNavStatus(data) {
  return request({
    url:'/nftType/updateNavStatus',
    method:'post',
    data:data
  })
}

export function getSuperior() {
  return request({
    url:'/nftType/getSuperior',
    method:'post',
  })
}

export function fetchListWithChildren() {
  return request({
    url:'/nftType/getNftTypeListByNftSearch/',
    method:'post'
  }).then( response => {
      let list = response.data;
      
      let productCateOptions = [];
      for (let i = 0; i < list.length; i++) {
        let children = [];
        if (list[i].children != null && list[i].children.length > 0) {
          for (let j = 0; j < list[i].children.length; j++) {
            children.push({ label: list[i].children[j].className, value: list[i].children[j].id });
          }
        }
       productCateOptions.push({ label: list[i].className, value: list[i].id, children: children });
      }
      return productCateOptions;
    })
}
